home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
asmexam.arc
/
ASCIIBIN.ASM
< prev
next >
Wrap
Assembly Source File
|
1984-07-10
|
3KB
|
156 lines
name ascbin
page 55,132
title 'ASCBIN - ASCII to binary conversion'
comment *
This program contains a pair of routines to convert
either decimal or hexidecimal ascii strings
to 32 bit binary integers
The main prog should load si with the address of the string
the proc leaves the 32 bit result in DX,CX
*
cseg segment para
assume cs:cseg,ds:cseg,ss:cseg
decnum: db '123','zzzz' ; z's are for extra locations
hexnum: db '1ae','zzzz'
org 100h
main proc near
mov ax,cs
mov ds,ax ; these two statements set up ds reg for debug
lea si,decnum
call decbin
lea si,hexnum
call hexbin
int 20h
main endp
decbin proc near
xor cx,cx
xor dx,dx
mov bx,-1
mov al,[si]
cmp al,'+'
jne decbin1
inc si
jmp decbin2
decbin1:
cmp al,'-'
jne decbin2
xor bh,bh
inc si
decbin2:
lodsb
or al,al
jz decbin8
cmp al,'.'
jz decbin4
cmp al,'9'
ja decbin7
cmp al,'0'
jb decbin7
or bl,bl
js decbin3
inc bl
decbin3:
push ax
mov di,cx
mov ax,dx
shl cx,1
rcl dx,1
shl cx,1
rcl dx,1
add cx,di
adc dx,ax
shl cx,1
rcl dx,1
pop ax
and ax,0fh
add cx,ax
adc dx,0
jmp decbin2
decbin4:
or bl,bl
jns decbin7
xor bl,bl
jmp decbin2
decbin7:
stc
ret
decbin8:
or bh,bh
jnz decbin9
not cx
not dx
add cx,1
adc dx,0
decbin9:
clc
ret
decbin endp
hexbin proc near
xor cx,cx
xor dx,dx
hexbin1:
lodsb
or al,al
jz hexbin8
cmp al,'0'
jb hexbin7
cmp al,'9'
jbe hexbin3
hexbin2:
or al,20h
cmp al,'f'
ja hexbin7
cmp al,'a'
jb hexbin7
add al,9
hexbin3:
shl cx,1
rcl dx,1
shl cx,1
rcl dx,1
shl cx,1
rcl dx,1
shl cx,1
rcl dx,1
and ax,0fh
or cx,ax
jmp hexbin1
hexbin7:
stc
ret
hexbin8:
clc
ret
hexbin endp
cseg ends
end main